﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using W.Warehouse.Domain.DTO.ReportlossesDto;
using W.Warehouse.Read.Api.Application.Command.ReportlossesCommand;

namespace W.Warehouse.Read.Api.Controllers
{
    /// <summary>
    /// 报损管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReportlossesController : ControllerBase
    {
        private readonly IMediator mediator;
        private ILogger<ReportlossesController> logger;


        public ReportlossesController(IMediator mediator, ILogger<ReportlossesController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }


        /// <summary>
        /// 显示查询产品信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageReportlosses>> GetReportShow([FromQuery] ReportlossesSelectCommand command)
        {
            ApiResult<PageReportlosses> result = new ApiResult<PageReportlosses>();
            try
            {
                logger.LogInformation("报损显示");
                result.Data = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                throw;
            }
        }

        /// <summary>
        /// 报损详情查看
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ReportlossesDto>> GetReportDetails([FromQuery] ReportlossesDetailsCommand command)
        {
            ApiResult<ReportlossesDto> result = new ApiResult<ReportlossesDto>();
            try
            {
                logger.LogInformation("报损详情查看");
                result.Data = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                throw;
            }
        }
    }
}
